<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;

class Temp extends Controller
{
    public function city()
    {
        $province = DB('area')->field('areaid,areaname')->where('parentid',0)->select();
        foreach ($province as $key => $value) {
            $city[$key]=DB('area')->field('areaid,areaname,parentid,pinyin')->where('parentid',$value['areaid'])->select();
        }
        // dump($city);
        $mu = DB('pinyin')->where('id','not in','15,21,22')->select();
        foreach ($mu as $k => $v) {
            $letter[$k]=DB('area')->field('areaid,areaname,letter_id,pinyin')->where('letter_id',$v['id'])->select();
        }
        $url="http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i",$url,$match);
        // dump($match);
        $this->assign('match',$match);
        $this->assign('letter',$letter);
        $this->assign('mu',$mu);
        $this->assign('city',$city);
        $this->assign('province',$province);
        return $this->fetch('index/address');
    }

    public function login()
    {
        return $this->fetch('index/login');
    }

    public function loginout()
    {
        $date = input()['name'];
        $dats = input()['pass'];
        $list = Db('user')
                    ->where('name', $date)
                    ->find();
        // dump($list);die;
        if($list == "" ){
            return $this->error('账号不存在！');
        }else if($list['password'] != md5($dats)){
            return $this->error('密码错误！');
        }else{
            $Session['id']=$list['id'];
            $Session['name']=$list['name'];
            Session('login_user',$Session);
            // dump(Session::get('login_user'));
            return $this->success('登陆成功！',url('index/Index/index'));
        }
    }

    public function tui()
    {
        Session::clear();
        return $this->success('退出成功！',url('index/Index/index'));
    }

    public function column()
	{
		$url="http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i",$url,$match);
     }
}
